#!/bin/bash

ex()
{
	echo "Running $1" >&2
	eval "$@" || exit 1
}

if [ $# -lt 1 ]
then
	echo -e "\r\n\tUsage: "`basename $0`" <filename>\r\n"
	exit 1
fi
	
dir=$(dirname $0)
file=$(basename $1 | cut -d. -f 1)
LDFLAGS="/usr/lib/crt1.o /usr/lib/crti.o -lc /usr/lib/crtn.o -dynamic /lib/ld-linux.so.2"

if [ "$2" != "-n" ]
then
	ex ${dir}/../../run "$1" -L $(dirname $1)/libic.sig > ${file}.s
fi
ex as -g -o ${file}.o ${file}.s
ex ld -g -o ${file} ${file}.o ${dir}/libic.a ${LDFLAGS}
ex ${dir}/${file}

